﻿using HandyControl.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace AgileLogistics.View.Baoxiu
{
    /// <summary>
    /// NewPage.xaml 的交互逻辑
    /// </summary>
    public partial class NewPage : Page
    {

        Model.DBContext dbContext = new Model.DBContext();

        ViewModel.RepairViewModel vm = new ViewModel.RepairViewModel();
        public NewPage()
        {
            InitializeComponent();

            vm = DataContext as ViewModel.RepairViewModel;

            //初始化数据
            vm.CurrRepair = new Model.Repairs() { Id=Comm.BillNoGenerate.GenerateWeiXiuNO() };
            vm.DepList = dbContext.DB.Queryable<Model.Depment>().ToList();
        }

        private void btn_Save_Click(object sender, RoutedEventArgs e)
        {
            vm.CurrRepair.State = "待处理";
            vm.CurrRepair.CreateTime = DateTime.Now;
            vm.CurrRepair.UserId= Comm.Temp.LoginUser.Id;
            vm.CurrRepair.UserName= Comm.Temp.LoginUser.Name;
             

            dbContext.DB.Insertable<Model.Repairs>(vm.CurrRepair).ExecuteCommand();
            Growl.SuccessGlobal("保存成功！");
            Comm.BillNoGenerate.WeixiuNoAdd();

            vm.CurrRepair = new Model.Repairs() { Id=Comm.BillNoGenerate.GenerateWeiXiuNO()};
        }

        private void btn_Cancle_Click(object sender, RoutedEventArgs e)
        {

        }
    }
}
